<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>search article</title>
<style type="text/css">
.articleTable {
	width:640px;
	border-top:1px dashed #cccccc;
	overflow:hidden;
}</style>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/js/pagination.js"></script>
<script type="text/javascript">
function Search(){
	this.articleSearchUrl="/wizard/search/article.html";
	this.userSearchUrl="/wizard/search/user.html";
	this.userSearchRefineUrl="/wizard/search/user/refine.html";
	this.beforeSendFunc=function(){
	}
	this.completeFunc=function(){
	}
	this.doError=function doError(request,state) {
		alert(state);
	}
	this.searchArticle=function(){
		var articleSearchKey=document.getElementById("articleSearchKey").value;
		if(articleSearchKey&&articleSearchKey!=""){
			var url=this.articleSearchUrl;
			var data="query="+articleSearchKey;
			var procArticleData=this.procArticleData; 
			document.getElementById("searchPaginationDiv").innerHTML="";
			/*$.ajax({
				url: url,
				data:data,
				type : "POST",
				dataType:"json",
				contentType: "application/x-www-form-urlencoded; charset=utf-8", 
				success : function(msg){
					procArticleData(msg);
				}
			});*/
			jQuery.extend(paginationSetting,{paramStr:data});
			PaginationUtils.paginationJsGen(paginationSetting);
			searchPagination.firstFunc();
		}
	};
	this.procTotalResults=function(total){
		var searchTotal=document.getElementById("searchTotalDiv");
		if(total>0){
			searchTotal.innerHTML="共有"+total+"搜索结果";
		}else{
			searchTotal.innerHTML="对不起，没有搜索结果！";
		}
	}
	this.procArticleData=function(msg){
		//alert(msg.page.total);
		this.procTotalResults(msg.page.total);
		var articles=msg.data;
		var searchArticles=document.getElementById("searchContentDiv");
		searchArticles.innerHTML="";
		for(var i=0;i<articles.length;i++){
			var article= articles[i];
			var innerHTML="";
			innerHTML+="<table class=\"articleTable\">";
			innerHTML+="<tr><td><a class=\"articleTitleA\" href=\"http://localhost:8080/skyline/article/view/"+article.id+".html\" targert=\"_blank\">"+article.title+"</a></td></tr>";
			innerHTML+="<tr><td>来自:<a href=\"http://localhost:8080/skyline\">"+article.ownerNickname+"</a>/";
			innerHTML+="<a href=\"http://localhost:8080/skyline/article/list/user/"+article.ownerId+".html\">日志分类</a>/";
			innerHTML+="<a href=\"http://localhost:8080/skyline/article/list/category/"+article.categoryId+".html\">"+article.categoryName+"</a>/</td></tr>";
			innerHTML+="<tr><td>"+article.digest+"</td></tr></table>";
			searchArticles.innerHTML+=innerHTML;
		}
	};
}
var search=new Search();
paginationSetting={
		firstFunc:"firstFunc",
		pageKey:"page",
		url:search.articleSearchUrl,
		pageDivId:"searchPaginationDiv",
		successFunc:"search.procArticleData",
		maxSize:"5",
		errorFunc:"search.doError",
		arcCur:"false",
		curClass:"cur1 cur2",
		curStyle:"font-size:12px",
		decStr:"%s",
		normalClass:"nor1 nor2",
		normalStyle:"font-size:14px",
		paramStr:"query=lucene",
		objId:"searchPagination",
		beforeSendFunc:"search.beforeSendFunc",
		completeFunc:"search.completeFunc"
	};
PaginationUtils.paginationJsGen(paginationSetting);

/*jQuery("document").ready(function(){
	searchPagination.firstFunc();
});*/
</script>
</head>
<body>
<input type="text" name="articleSearchKey" id="articleSearchKey"> <input type="button" onclick="search.searchArticle()" value="搜索">
<div id="searchResultDiv">
<div id="searchTotalDiv">
</div>
<div id="searchPaginationDiv">
</div>
<div id="searchContentDiv">
</div>
</div>
</body>
</html>